﻿

Ext.define('app.ux.PagePrmStore',
{
    extend: 'Ext.data.Store',
    autoLoad: true,
    remoteSort: true,
    url: '',
    filter: {},
    proxy: {
        type: 'ajax',
        url: '',
        reader: {
            type: 'json',
            rootProperty: 'result.items',
            totalProperty: 'result.totalCount'
        }
    },
    listeners: {
        beforeload: function (store, opt, evt) {

            store.proxy.url = store.url;

            var sort = [];
            if (opt._sorters && opt._sorters[0]._id && opt._sorters[0]._direction) {
                for (var i = 0; i < opt._sorters.length; i++) {
                    var sorter = opt._sorters[i];
                    sort.push(sort._id + " " + sorter._direction);
                }
            } else {
                sort.push("id DESC");
            }
            var filter = store.filter;
            filter.Sorting = sort.toString();
            filter.SkipCount = opt._start;
            filter.MaxResultCount = opt._limit;
            store.proxy.extraParams = filter;
        }
    }
});
